import Vue from 'vue'
// import Vuex from 'vuex'
import Vuex from '../vuex/index'

//通过应用层反推原理
Vue.use(Vuex) //imstall => 注册流程 Store
// 1．兄弟组件传值2．跨级组件传值
//events-bus数据量不大，切不需要同步
export default new Vuex.Store({
  //数据源 仓库
  state: {
    name: "思言大保健中心",
    age: 18
  },
  //相当于vue的计算属性
  getters: {
    //Object.definProperty()
    addName(state) {
      return `${state.name}来了男宾一位`
    }
  },
  //提交数据 修改
  mutations: {
    syncAdd(state, payload) {
      state.age += payload
    },
    syncReduce(state, payload) {
      state.age -= payload
    }
  },
  //做异步操作 => mutations
  actions: {
    asyncReduce({commit}, payload) {
      setTimeout(() => {
        commit("syncReduce", payload)
      }, 1000);
    }
  },
  // vuex模块大
  modules: {}
})